import java.io.Serializable;
import java.time.LocalDateTime;

// 枚举：放映厅类型
enum HallType {
    GOLD("黄金厅", 8, 10),
    SILVER("白银厅", 10, 12),
    JADE("翡翠厅", 7, 8),
    DIAMOND("钻石厅", 7, 8),
    GEM("宝石厅", 8, 9);

    private final String name;
    private final int rows;
    private final int cols;

    HallType(String name, int rows, int cols) {
        this.name = name;
        this.rows = rows;
        this.cols = cols;
    }

    public String getName() {
        return name;
    }

    public int getRows() {
        return rows;
    }

    public int getCols() {
        return cols;
    }

    public int getCapacity() {
        return rows * cols;
    }
}

// 场次类
class Screening implements Serializable {
    private String screeningId;
    Movie movie;
    private HallType hall;
    private LocalDateTime startTime;
    double price;
    private boolean[][] seats; // 座位状态矩阵

    public Screening(String screeningId, Movie movie, HallType hall, LocalDateTime startTime, double price) {
        this.screeningId = screeningId;
        this.movie = movie;
        this.hall = hall;
        this.startTime = startTime;
        this.price = price;
        this.seats = new boolean[hall.getRows()][hall.getCols()];
    }

    // 检查座位是否可用
    public boolean isSeatAvailable(int row, int col) {
        return !seats[row][col];
    }

    // 占用座位
    public boolean occupySeat(int row, int col) {
        if (row < 0 || row >= hall.getRows() || col < 0 || col >= hall.getCols()) {
            return false;
        }
        if (isSeatAvailable(row, col)) {
            seats[row][col] = true;
            return true;
        }
        return false;
    }

    // 释放座位
    public boolean releaseSeat(int row, int col) {
        if (row < 0 || row >= hall.getRows() || col < 0 || col >= hall.getCols()) {
            return false;
        }
        if (!isSeatAvailable(row, col)) {
            seats[row][col] = false;
            return true;
        }
        return false;
    }

    // 获取可用座位数
    public int getAvailableSeatsCount() {
        int count = 0;
        for (boolean[] row : seats) {
            for (boolean seat : row) {
                if (!seat) count++;
            }
        }
        return count;
    }

    // 打印座位图
    public void printSeatMap() {
        System.out.print("   ");
        for (int col = 1; col <= hall.getCols(); col++) {
            System.out.printf("%-4d", col);
        }
        System.out.println();

        for (int row = 0; row < hall.getRows(); row++) {
            System.out.printf("%-3d", row + 1);
            for (int col = 0; col < hall.getCols(); col++) {
                System.out.print(seats[row][col] ? "[X] " : "[ ] ");
            }
            System.out.println();
        }
    }

    // Getters
    public String getScreeningId() { return screeningId; }
    public Movie getMovie() { return movie; }
    public HallType getHall() { return hall; }
    public LocalDateTime getStartTime() { return startTime; }
    public double getPrice() { return price; }
}
